<template>
    <div>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell mui-media" v-for="item in newsList" :key="item.id">
                <router-link  :to="'/home/newsinfo?id='+item.id">
                    <img class="mui-media-object mui-pull-left" :src="item.pic">
                    <div class="mui-media-body">
                        <h1>{{ item.title }}</h1>
                        <p class='mui-ellipsis'>
                            <span>发表时间：{{ item.dateAdd | dateFormat('YYYY-MM-DD') }}</span>
                            <span>浏览次数：{{ item.views }}</span>
                        </p>
                    </div>
                </router-link>
            </li>
        </ul>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                newsList: []
            }
        },
        created() {
            this.getNewsList()
        },
        methods: {
            getNewsList() {
                this.$http.post('/cms/news/list').then( (res)=> {
                    if(res.data.code === 0) {
                        this.newsList = res.data.data
                    }else{
                        this.$toast(res.data.msg)
                    }
                })
            }
        },
    }
</script>

<style lang="scss" scoped>
.mui-media-body{
    h1{
        font-size: 16px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .mui-ellipsis{
        display: flex;
        justify-content: space-between;
        font-size: 14px;
    }
}
.mui-table-view-cell{
    a:not(.mui-btn).mui-active{
        background: #fff;
    }
}
</style>